package 线程池.父子线程问题;

import com.google.common.util.concurrent.ThreadFactoryBuilder;

import java.util.concurrent.*;

/**
 * @author caihe
 * @date 2022/7/19 11:00
 */
public class ThreadPool {


    private static final ThreadFactory threadFactory = new ThreadFactoryBuilder()
            .setNameFormat("异步线程池中的线程" + "-%d")
            .setDaemon(true).build();

    /**
     * CallerRunsPolicy 拒绝任务的处理程序，直接在 {@code execute} 方法的调用线程中运行被拒绝的任务，除非执行程序已关闭，在这种情况下，任务将被丢弃。
     */
    public static final ExecutorService executorService = new ThreadPoolExecutor(
            2, 
            2,
            5000, 
            TimeUnit.MILLISECONDS,
            new ArrayBlockingQueue<>(100),
            threadFactory,
            new ThreadPoolExecutor.CallerRunsPolicy());

    public static final ExecutorService executorService1 = new ThreadPoolExecutor(
            2,
            2,
            5000,
            TimeUnit.MILLISECONDS,
            new ArrayBlockingQueue<>(100),
            threadFactory,
            new ThreadPoolExecutor.CallerRunsPolicy());
    
}
